package cn.lanqiao.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import cn.lanqiao.entiy.Student;
import cn.lanqiao.entiy.User;

import java.awt.Toolkit;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.Font;
import java.awt.HeadlessException;

import javax.swing.JDesktopPane;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.awt.event.ActionEvent;

public class MainFrmUser extends JFrame {

	private JPanel contentPane;
	JDesktopPane desktopPane;
	static User user = null;
	static Student student=null;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainFrmUser frame = new MainFrmUser(user,student);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	
	public MainFrmUser(User lg_user,Student lg_student) {
		this.user = lg_user;
		this.student=lg_student;
		setTitle("阿强健身房/学员后台");
		setIconImage(Toolkit.getDefaultToolkit().getImage(MainFrmUser.class.getResource("/cn/lanqiao/img/logo.png")));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1054, 689);
		
		//居中
		MainFrmUser.this.setLocationRelativeTo(null);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnNewMenu = new JMenu("报名");
		mnNewMenu.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		menuBar.add(mnNewMenu);
		
		JMenuItem TeacherList = new JMenuItem("教练列表");
		TeacherList.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				//解决可以打开多个同一窗体的问题
				//容器中有窗体：激活窗体；   没有；创建窗体
				String tilte="教练列表";
				//第1步；找到容器中所有子窗体
				JInternalFrame[] childFrames=desktopPane.getAllFrames();
			 
				//第2步；遍历，查找
				boolean isExists=false;//设置boolean对象，判断窗体是否打开，以此解决打开多个窗体的问题
				for(JInternalFrame f: childFrames) {
				   if(f.getTitle().equals(tilte)) {
					   try {
						   //找到已经创建的窗体激活
						f.setSelected(true);
						isExists=true;
					} catch (PropertyVetoException e1) {
						e1.printStackTrace();
					}
				   }	
				}
				if(!isExists) {
					//3.连接教练表窗体
					TeacherListFrm teacherFrm=new TeacherListFrm();
					teacherFrm.setVisible(true);
				    desktopPane.add(teacherFrm);
				System.out.println(isExists);
				}
				
				//3.连接教练表窗体
//				TeacherListFrm teacherFrm=new TeacherListFrm();
//				teacherFrm.setVisible(true);
//			    desktopPane.add(teacherFrm);
			
			}
		});
		TeacherList.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		mnNewMenu.add(TeacherList);
		
		JMenuItem mntmNewMenuItem = new JMenuItem("立即报名");
		mntmNewMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			//获取学员账号信息user
				User us1=getUser();
			//给学员信息（文本框）赋值
				
			
			}
		});
		mntmNewMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		mnNewMenu.add(mntmNewMenuItem);
		
		JMenu mnNewMenu_1 = new JMenu("账号管理");
		mnNewMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		menuBar.add(mnNewMenu_1);
		
		JMenuItem mntmNewMenuItem_1 = new JMenuItem("修改密码");
		mntmNewMenuItem_1.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		mnNewMenu_1.add(mntmNewMenuItem_1);
		
		JMenu mnNewMenu_2 = new JMenu("关于我们");
		mnNewMenu_2.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		menuBar.add(mnNewMenu_2);
		
		JMenuItem mntmNewMenuItem_2 = new JMenuItem("健身房简介");
		mntmNewMenuItem_2.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		mnNewMenu_2.add(mntmNewMenuItem_2);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
	     desktopPane = new JDesktopPane();
		desktopPane.setBackground(new Color(240, 248, 255));
		contentPane.add(desktopPane, BorderLayout.CENTER);
	}


	//获取学员账号密码user
	public User getUser() {
	  return this.user;
	}

}
